{php include wl_template('common/header');}
<ul class="nav nav-tabs">
    <li><a href="{php echo web_url('live/goods/goodsList')}">商品列表</a></li>
    <li class="active"><a href="javascript:;">编辑商品</a></li>
</ul>
<div class="app-content">
    <div class="app-filter">
        <div class="alert alert-warning">
            {if $status == 0}
                可以更新所有信息
            {else}
                仅允许更新价格类型与价格信息
            {/if}
        </div>
    </div>
    <div class="app-form">
        <div class="panel panel-default">
            <form class="form-horizontal form-validate" method="post">
                <!--商品状态，0：未审核。1：审核中，2：审核通过，3：审核驳回-->
                <!--审核通过的商品仅允许更新价格类型与价格，未审核的商品允许更新所有字段-->
                {if $status == 0}
                    <!-- 可以更新所有信息 -->
                    <div class="form-group" id="goods">
                        <label class="col-sm-2 control-label must">选择商品</label>
                        <div class="col-sm-9 is_judge" is_judge="false">
                            <div class="input-group">
                                <input type="text" placeholder="请选择商品!" name="data[goods_name]" readonly="readonly" value="{$info['goods_name']}" class="form-control selectGoods_name" autocomplete="off">
                                <input type="text" placeholder="请选择商品!" name="data[goods_id]" readonly="readonly" value="{$info['goods_id']}" class="form-control hide selectGoods_id" autocomplete="off">
                                <input type="text" placeholder="请选择商品!" name="data[goods_plugin]" readonly="readonly" value="{$info['goods_plugin']}" class="form-control hide selectGoods_plugin" autocomplete="off">
                                <input type="text" placeholder="请选择商品!" name="data[sid]" readonly="readonly" value="{$info['sid']}" class="form-control hide selectGoods_sid" autocomplete="off">
                                <span class="input-group-btn">
                                        <button class="btn btn-default" type="button" data-toggle="selectGoods">选择商品</button>
                                    </span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品图片</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <input type="text" name="data[goods_img]" value="{$params['goods_img']}" class="form-control" autocomplete="off" id="cimg-data_goods_img">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button" data-toggle="selectAttachment" data-input="#cimg-data_goods_img" data-img="#pimg-data_goods_img">选择图片</button>
                                </span>
                            </div>
                            <div class="input-group " style="margin-top:.5em;">
                                <img src="{$params['goods_img']}" id="pimg-data_goods_img" class="img-responsive img-thumbnail" width="150" onerror="this.src='{IMAGE_NOPIC_SMALL}'" data-times="1">
                                <em class="close" style="position:absolute; top: 0px; right: -14px;" onclick="$('#cimg-data_goods_img').val('');$('#pimg-data_goods_img').attr('src','');">×</em>
                            </div>
                            <span class="help-block">图片尺寸最大300像素*300像素，如果不传图片则默认使用当前商品logo图片</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must ">商品名称</div>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" minlength="3" maxlength="14" name="data[title]" value="{$params['title']}"/>
                            <div class="help-block">最少3汉字6字母;最大14个汉字28字母。不填则默认使用商品当前名称，超出长度则截取前14位。</div>
                        </div>
                    </div>
                {else}
                    <!--仅允许更新价格类型与价格信息-->
                    <div class="form-group" id="goods">
                        <label class="col-sm-2 control-label must">选择商品</label>
                        <div class="col-sm-9 is_judge" is_judge="false">
                            <div class="input-group">
                                <input type="text" placeholder="请选择商品!" readonly="readonly" value="{$info['goods_name']}" class="form-control selectGoods_name" autocomplete="off">
                                <input type="text" placeholder="请选择商品!" name="data[goods_id]" readonly="readonly" value="{$info['goods_id']}" class="form-control hide selectGoods_id" autocomplete="off">
                                <input type="text" placeholder="请选择商品!" readonly="readonly" value="{$info['goods_plugin']}" class="form-control hide selectGoods_plugin" autocomplete="off">
                                <input type="text" placeholder="请选择商品!" readonly="readonly" value="{$info['sid']}" class="form-control hide selectGoods_sid" autocomplete="off">
                                <span class="input-group-btn">
                                        <button class="btn btn-default" type="button" disabled="disabled">选择商品</button>
                                    </span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品图片</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <input type="text" value="{$params['goods_img']}" disabled="disabled" class="form-control" autocomplete="off">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button" disabled="disabled">选择图片</button>
                                </span>
                            </div>
                            <div class="input-group " style="margin-top:.5em;">
                                <img src="{$params['goods_img']}" class="img-responsive img-thumbnail" width="150" onerror="this.src='{IMAGE_NOPIC_SMALL}'" data-times="1">
                            </div>
                            <span class="help-block">图片尺寸最大300像素*300像素，如果不传图片则默认使用当前商品logo图片</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must ">商品名称</div>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" minlength="3" maxlength="14" disabled="disabled" value="{$params['title']}"/>
                            <div class="help-block">最少3汉字6字母;最大14个汉字28字母。不填则默认使用商品当前名称，超出长度则截取前14位。</div>
                        </div>
                    </div>
                {/if}
                <!-- 价格类型 -->
                <div class="form-group">
                    <label class="col-sm-2 control-label"><span class="form-must">*</span>价格类型</label>
                    <div class="col-sm-9">
                        <label class="radio-inline">
                            <input type="radio" name="data[price_type]" value="1" {if $params['price_type'] == 1}checked="checked"{/if}> 一口价
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="data[price_type]" value="2" {if $params['price_type'] == 2}checked="checked"{/if}> 价格区间
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="data[price_type]" value="3" {if $params['price_type'] == 3}checked="checked"{/if}> 折扣价
                        </label>
                        <div class="help-block">默认使用一口价类型。价格为当前商品价格</div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-2 control-label" id="price">
                        {if $params['price_type'] == 1}
                            售价
                        {elseif $params['price_type'] == 2}
                            最低价
                        {elseif $params['price_type'] == 3}
                            原价
                        {/if}
                    </div>
                    <div class="col-sm-9">
                        <input class="form-control" type="number" step="0.01" name="data[price]" value="{$params['price']}"/>
                    </div>
                </div>
                <div class="form-group {if $params['price_type'] == 1}hide{/if}">
                    <div class="col-sm-2 control-label" id="price2">
                        {if $params['price_type'] == 1}

                        {elseif $params['price_type'] == 2}
                            最高价
                        {elseif $params['price_type'] == 3}
                            现价
                        {/if}
                    </div>
                    <div class="col-sm-9">
                        <input class="form-control" type="number" step="0.01" name="data[price2]" value="{$params['price2']}"/>
                    </div>
                </div>
                <!--提交按钮-->
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-9">
                        <input type="hidden" name="goods_id" value="{$params['goods_id']}" />
                        <input type="hidden" name="status" value="{$status}" />
                        <input type="hidden" name="token" value="{$_W['token']}" />
                        <input type="submit" name="submit" value="提交" class="btn btn-primary col-sm-1 min-width" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    /**
     * 更换价格类型
     */
    $("[name='data[price_type]']").on('change',function () {
        //基本参数信息获取
        let _this = $(this),
            _val  = _this.val();
        //根据价格类型进行对应的操作
        if(_val == 1){
            //标题信息替换
            $("#price").html('售价');
            $("#price2").html('');
            //隐藏价格二
            $("#price2").parent(".form-group").addClass('hide');
        }else if(_val == 2){
            //标题信息替换
            $("#price").html('最低价');
            $("#price2").html('最高价');
            //显示价格二
            $("#price2").parent(".form-group").removeClass('hide');
        }else if(_val == 3){
            //标题信息替换
            $("#price").html('原价');
            $("#price2").html('现价');
            //显示价格二
            $("#price2").parent(".form-group").removeClass('hide');
        }
    });
    /**
     * 提交判断信息
     * @returns {boolean}
     */
    function formcheck(){
        let gid = $("[name='data[goods_id]']").val();
        if(!gid){
            tip.alert('请选择商品！');
            return false;
        }
    }
</script>
{php include wl_template('common/footer');}
